package com.vegetable.config;

import cn.hutool.core.lang.UUID;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import org.springframework.context.annotation.Bean;

@org.springframework.context.annotation.Configuration
public class QiniuConfig {

    private static final String accessKey = "H9jlZIdZVZfXbDBuHb3etglRZxn1H1TVqUIMmQNP";

    private static final String secretKey = "DESyGe3tMFNPgnppeDZO1Jghw9gJBMZnjUR2PF4y";

    private static final String bucket = "ds-crm";

    private static final String domain = "";

    @Bean
    public Auth auth() {
        return Auth.create(accessKey, secretKey);
    }

    @Bean
    public Configuration configuration() {
        return Configuration.create(Region.region1());
    }

    @Bean
    public UploadManager uploadManager(Configuration configuration) {
        return new UploadManager(configuration);

    }

    @Bean
    public String token() {
        return auth().uploadToken(bucket, UUID.fastUUID().toString(),
                7200,  // 有效期（秒）
                new StringMap().put("insertOnly", 1) // 禁止覆
        );

    }

    @Bean
    public String domain() {
        return domain;
    }
}
